package com.ms.p2p.service.impl;


import com.ms.p2p.bean.PageBean;
import com.ms.p2p.dao.AdvertDao;
import com.ms.p2p.entity.content.Advert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdvertServiceImpl{
	@Autowired
	private AdvertDao advertDao;
	@CacheEvict(value="advert",allEntries=true)
	public int update(Advert map) {
		return advertDao.update(map);
	}
	@CacheEvict(value="advert",allEntries=true)
	public int insert(Advert map) {
		return advertDao.insert(map);
	}

	@Cacheable(value="advert",key="'is_display'+#category+'category'+#category")
	public List<Advert> getPPTList(Integer is_display, Integer category) {
		return advertDao.findPager(null, null, is_display, category, 1, null);
	}

	@CacheEvict(value="advert",allEntries=true)
	public int delete(int id) {
		return advertDao.deleteById(id);

	}
	@Cacheable(value="advert",key="'id'+#id")
	public Advert selectById(int id) {
		return advertDao.get(id+"");
	}

	public List<Advert> findPager(String addDate_begin, String addDate_end, Integer dis_play,Integer category,PageBean page) {
		return advertDao.findPager(addDate_begin,addDate_end,dis_play,category,page.getBegin(),page.getPageSize());
	}

	public int findCount(String addDate_begin, String addDate_end,Integer dis_play,Integer category) {
		return advertDao.findCount(addDate_begin,addDate_end,dis_play,category);
	}
}
